/**
 *  Copyright (C) 2013  Piotr Szczepa�ski
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package edu.pw.elka.gtsna.graph;

import edu.pw.elka.gtsna.graph_creator.GraphCreator;

/**
 * @author Piotr Lech Szczepa�ski
 * @author P.Szczepanski@ii.pw.edu.pl 
 *
 */
public class WeightedUndirectedGraph extends UndirectedGraph {

	private double[][] weights;
	
	public WeightedUndirectedGraph(int numOfNodes){
		super(numOfNodes);
		weights = new double[numOfNodes+1][numOfNodes+1];
	}
	
	public WeightedUndirectedGraph(GraphCreator creator){	
		this(creator.getNumOfNodes());
		for(Edge e: creator){
			addEdge((WeightedEdge)e);
			
		}
	}

	public void addEdge(WeightedEdge edge){
		if (!areNeighbours(edge.getFrom(), edge.getTo())) {
			addEdge(edge.getFrom(), edge.getTo(),edge.getWeight());
		}
		
	}
	
	public double getWeight(int n1, int n2){
		return weights[n1][n2];
	}

	public double getWeight(int n1){
		return weights[n1][n1];
	}
	
	public void setWeight(int n1, double weight){
		weights[n1][n1]=weight;
	}
	
	public void addEdge(int u, int v, double weight){
		super.addEdge(u,v);

		weights[u][v] = weight;
		weights[v][u] = weight;

	}
	
}
